package Demo1;

import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 34255
 * Date: 2024-06-07
 * Time: 16:01
 */
public class Test {

    public static int[][] get2Array(int n){
        int[][] array = new int[n][];
        for(int i = 0; i < n; i++) {
            array[i] = new int[n-i];
        }
        return array;
    }
    public static void main1(String[] args) {
        int[][] array = get2Array(5);
        System.out.println(array.length);
        for (int i = 0; i < array.length; i++) {
            for (int j = 0; j < array[i].length; j++) {
                System.out.print(array[i][j] + " ");
            }
            System.out.println();
        }
    }
}
//轮转数组
class Solution1 {
    public void rotate(int[] nums, int k) {
        int tmp = 0;
        for(int i = 1;i <= k;i++){
            tmp = nums[nums.length - 1];
            for(int j = nums.length - 1;j > 0 ;j--){
                nums[j] = nums[j - 1];
            }
            nums[0] = tmp;
        }
    }
}
//消失的数字
class Solution2 {
    public int missingNumber(int[] nums) {
        int[] num = new int[nums.length + 1];
        for(int i = 0;i < nums.length;i++){
            num[nums[i]] = 1;
        }
        for(int i = 0;i < num.length;i++){
            if(num[i] == 0)
                return i;
        }
        return 0;
    }
}
//删除有序数组中的重复项
class Solution3 {
    public int removeDuplicates(int[] nums) {
        int left = 1;
        for(int right = 1;right < nums.length;right++){
            while(nums[left - 1] == nums[right]){
                right++;
                if(right == nums.length){
                    return left;
                }
            }
            //赋值
            nums[left++] = nums[right];
            // nums[left++] = nums[right];
            // val = nums[left];//error
        }
        return left;
    }
}
//移除元素
class Solution4 {
    public int removeElement(int[] nums, int val) {
        int pf1 = 0;
        int pf2 = 0;
        while(pf1 < nums.length){
            if(nums[pf2] == val){
                while(nums[pf1] == val){
                    pf1++;
                    if(pf1 == nums.length){
                        return pf2;
                    }
                }
                int tmp = nums[pf2];
                nums[pf2] = nums[pf1];
                nums[pf1] = tmp;
                pf1++;
                pf2++;
            }else{
                pf1++;
                pf2++;
            }
        }
        return pf2;
    }
}
//合并两个有序数组
class Solution {
    public void merge(int[] nums1, int m, int[] nums2, int n) {
        // if(m == 0){//局部变量对实参没有影响
        //     nums1 = nums2;
        // }

        int pf = m  + n - 1;
        int pf1 = m - 1;
        int pf2 = n - 1;
        while(pf1 >= 0 && pf2 >= 0){
            if(nums1[pf1] >= nums2[pf2]){
                nums1[pf--] = nums1[pf1--];
            }else{
                nums1[pf--] = nums2[pf2--];
            }
        }
        while(pf2 >= 0){
            nums1[pf--] = nums2[pf2--];
        }
    }
}